package com.acegear.horizon.domain.models.jpa;

import com.acegear.horizon.domain.models.constraint.UserPostType;
import com.acegear.horizon.domain.models.jpa.convert.ContentPartConverter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.List;

/**
 * Created by mercury on 2016/12/22.
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(indexes = @Index(columnList = "clubId,userId"))
public class UserPost {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @JsonIgnore
    private Long id;

    @Column(unique = true)
    private Long postId;

    @Column
    private Long clubId;

    @Column
    private Long userId;

    @Column
    @Enumerated(EnumType.ORDINAL)
    private UserPostType postType;

    @Column(columnDefinition = "TEXT")
    @Convert(converter = ContentPartConverter.class)
    private List<ContentPart> contents;

    /**
     * 帖子的发布状态(已发布，草稿中，已删除)
     */
//    private PostPublishState postPublishState;

    private boolean deleted;
    
    @Column
    private String rank; 

    @CreatedDate
    @Column
    private Long createAt;

    @LastModifiedDate
    @Column
    private Long updateAt;

    public UserPost() {
    }


    public UserPost(Long postId, Long clubId, Long userId, UserPostType postType, List<ContentPart> contents, boolean deleted) {
        this.postId = postId;
        this.clubId = clubId;
        this.userId = userId;
        this.postType = postType;
        this.contents = contents;
        this.deleted = deleted;
    }

    public Long getPostId() {
        return postId;
    }

    public void setPostId(Long postId) {
        this.postId = postId;
    }

    public Long getCreateAt() {
        return createAt;
    }

    public Long getUpdateAt() {
        return updateAt;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getClubId() {
        return clubId;
    }

    public void setClubId(Long clubId) {
        this.clubId = clubId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public UserPostType getPostType() {
        return postType;
    }

    public void setPostType(UserPostType postType) {
        this.postType = postType;
    }

    public List<ContentPart> getContents() {
        return contents;
    }

    public void setContents(List<ContentPart> contents) {
        this.contents = contents;
    }

//    public PostPublishState getPostPublishState() {
//        return postPublishState;
//    }
//
//    public void setPostPublishState(PostPublishState postPublishState) {
//        this.postPublishState = postPublishState;
//    }


    public String getRank() {
		return rank;
	}


	public void setRank(String rank) {
		this.rank = rank;
	}

    public boolean isDeleted() {
        return deleted;
    }


	public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }
}
